<?php
/**************************************************************************
 *
 *   Copyright 2010 American Public Media Group
 *
 *   This file is part of AIR2.
 *
 *   AIR2 is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   AIR2 is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with AIR2.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************/

/**
 * Question
 *
 * Single Questions sent to a Source as part of an Inquiry.
 *
 * @property integer $ques_id
 * @property integer $ques_inq_id
 * @property integer $ques_dis_seq
 * @property string $ques_type
 * @property string $ques_value
 * @property string $ques_choices
 * @property integer $ques_cre_user
 * @property integer $ques_upd_user
 * @property timestamp $ques_cre_dtim
 * @property timestamp $ques_upd_dtim
 * @property string $ques_uuid
 * @property Inquiry $Inquiry
 * @property Doctrine_Collection $SrcResponse
 * @author rcavis
 * @package default
 */
class Question extends AIR2_Record {

    // question types
    public static $TYPE_TEXT = 'T';
    public static $TYPE_DATE = 'D';
    public static $TYPE_FILE = 'F';
    public static $TYPE_PICK_SINGLE = 'S';
    public static $TYPE_PICK_MULTIPLE = 'M';

    /**
     * Set the table columns
     */
    public function setTableDefinition() {
        $this->setTableName('question');
        $this->hasColumn('ques_id', 'integer', 4, array(
                'primary' => true,
                'autoincrement' => true,
            ));
        $this->hasColumn('ques_inq_id', 'integer', 4, array(
                'notnull' => true,
            ));
        $this->hasColumn('ques_dis_seq', 'integer', 2, array(
                'default' => 20,
                'notnull' => true,
            ));
        $this->hasColumn('ques_type', 'string', 1, array(
                'fixed' => true,
                'notnull' => true,
                'default' => Question::$TYPE_TEXT,
            ));
        $this->hasColumn('ques_value', 'string', null, array(
                'notnull' => true,
            ));
        $this->hasColumn('ques_choices', 'string', null, array(

            ));
        $this->hasColumn('ques_cre_user', 'integer', 4, array(
                'notnull' => true,
            ));
        $this->hasColumn('ques_upd_user', 'integer', 4, array(

            ));
        $this->hasColumn('ques_cre_dtim', 'timestamp', null, array(
                'notnull' => true,
            ));
        $this->hasColumn('ques_upd_dtim', 'timestamp', null, array(

            ));
        $this->hasColumn('ques_uuid', 'string', 12, array(
                'fixed' => true,
                'notnull' => true,
                'unique' => true,
            ));

        $this->index('ques_ix_2', array(
                'fields' => array('ques_inq_id', 'ques_dis_seq'),
                'type' => 'unique'
            ));

        parent::setTableDefinition();
    }



    /**
     * Set table relations
     */
    public function setUp() {
        parent::setUp();
        $this->hasOne('Inquiry', array(
                'local' => 'ques_inq_id',
                'foreign' => 'inq_id',
                'onDelete' => 'CASCADE',
            ));
        $this->hasMany('SrcResponse', array(
                'local' => 'ques_id',
                'foreign' => 'sr_ques_id'
            ));
    }


}
